<?php

include_once 'actions.class.php';

class Odbc_conn implements Actions {

    public $dbconn = null;

    function Odbc_conn($dbconn) {
        $this->setDbconn($dbconn);
    }

    public function close($dbconn) {
        @odbc_close($dbconn);
    }

    public function connect($stringConn) {
        if (!$conn = ini_get('allow_persistent') ? @odbc_connect($stringConn, '', '') : @odbc_connect($stringConn, '', ''))
            echo 'No se pudo establecer conexion con la base de datos';
        return ($conn);
    }

    public function execute($sql) {
        $res = @odbc_exec($this->dbconn, $sql);
        if (odbc_error ()) {
            echo odbc_errormsg($this->dbconn);
            $this->close($this->dbconn);
            exit();
        }
        return $res;
    }

    public function fetchArrayAssoc($arr) {
        $rsp = array();
        $i = 0;
        while ($mArrayResult = @odbc_fetch_array($arr)) {
            foreach ($mArrayResult as $mIndex => $mValue) {
                $rsp[$i] [strtolower($mIndex)] = $mValue;
            }
            $i++;
        }
        return ($rsp);
    }

    public function fetchArrayBoth($arr) {
        $rsp = array();
        $i = 0;
        while ($mArrayResult = @odbc_fetch_array($arr)) {
            $k = 0;
            foreach ($mArrayResult as $mIndex => $mValue) {
                $rsp[$i] [strtolower($mIndex)] = $mValue;
                $rsp[$i] [$k] = $mValue;
                $k++;
            }
            $i++;
        }
        return ($rsp);
    }

    public function fetchArrayNum($arr) {
        $rsp = array();
        $i = 0;
        while ($mArrayResult = @odbc_fetch_array($arr)) {
            $k = 0;
            foreach ($mArrayResult as $mIndex => $mValue) {
                $rsp[$i] [$k] = $mValue;
                $k++;
            }
            $i++;
        }
        return ($rsp);
    }

    public function setDbconn($dbconn) {
        $this->dbconn = $dbconn;
    }

}

?>
